// components/component-tag-name.js
const app = getApp()
let Axios = require('../../common/js/ajax.js');
let Mtils = require('../../common/js/Mtils.min.js');
Mtils = Mtils.Mtils
Component({
	/**
	 * 组件的属性列表
	 */
	properties: {},
	/**
	 * 组件的初始数据
	 */
	data: {
		loading: false
	},
	ready: function() {	
	},
	/**
	 * 组件的方法列表
	 */
	methods: {
		bubbling: function() {},
		handleCloseTap: function() {
			this.loadIng()
		},
		loadIng() {
			this.setData({
				loading: false
			})
		},
		showIng() {
			this.setData({
				loading: true
			})
		},
		getUserInfo: function(e) {
			//console.log(e)
			let errorCode = e.detail.errMsg;
			if (errorCode == 'getUserInfo:fail auth deny') {
				wx.showModal({
					title: "提示",
					content: "很遗憾您无法访问甄藏汇",
					showCancel: false,
					success(res) {
						if (res.confirm) {
							//点击确定以后执行方法或者跳转
							wx.reLaunch({
								url: '/pages/indexList/indexList'
							})
						}
					}
				})
			} else {
				const obj = {};
				const userDataObj = e.detail.userInfo;
				obj.openid = app.globalData.openid;
				obj.nickName = userDataObj.nickName;
				obj.avatarUrl = userDataObj.avatarUrl;
				app.globalData.nickName = userDataObj.nickName;
				app.globalData.avatarUrl = userDataObj.avatarUrl
				var _this = this;
				wx.login({
					success(res) {
						if (res.code) {
							Axios.post(app.globalData.baseUrl + 'App/Login/Login/wx_login', {
								code: res.code,
								nickname: userDataObj.nickName,
								user_img: userDataObj.avatarUrl
							}, (res) => {
								console.log(res)
								if (res.status == 1) {
									var data = res.info
									obj.uid = data.id;
									app.globalData.uid = data.id;
									obj.identifier = data.identifier
									obj.identifierNick = data.identifierNick
									obj.userSig = data.userSig
									app.globalData.identifier = data.identifier
									app.globalData.identifierNick = data.identifierNick
									app.globalData.userSig = data.userSig									
									wx.setStorageSync('userInfo', obj);
									wx.reLaunch({
										url: '/pages/indexList/indexList'
									})
								}
							})
						} else {
							wx.showModal({
								content: '登录失败',
								showCancel: false,
							})
						}
					},
					fail() {
						wx.showModal({
							content: '登录失败',
							showCancel: false,
						})
					}
				})
			}
		},
		handleRefuseTap: function() {
			this.loadIng()
		},
		showModal: function(error) {
			wx.showModal({
				content: error.msg,
				showCancel: false,
			})
		}		
	}
})
